import type { RouteRecordRaw } from "vue-router";
import NotFound from '@/views/404.vue'

// 定义路由 meta 类型增强
declare module 'vue-router' {
  interface RouteMeta {
    title: string;          // 页面标题（必须）
    icon?: string;         // 图标类名（可选）
    fixed?: boolean;       // 是否固定在标签页（可选）
    hidden?: boolean;      // 是否隐藏菜单（可选）
    breadcrumb?: Array<{   // 面包屑配置（可选）
      title: string;
      path?: string;       // 可点击的面包项需要 path
    }>;
    isBasic?: boolean;     // 是否基础路由（如登录页）
  }
}

export const routes: RouteRecordRaw[] = [
  {
    path: "/login",
    name: "Login",
    component: () => import("@/views/login/index.vue"),
    meta: {title: "登录",
      isBasic: true,
    },
  },
  // 其他基础路由...
  {
    path: "/",
    name: "Layout",
    component: () => import("@/components/layout/index.vue"),    
    meta: {
      title: "404"
    },
   redirect: to => to.path === '/' ? '/home' : '/404', // 添加这行实现自动重定向
    children: [
      {
        path: "/home",
        name: "Home",
        component: () => import("@/views/home.vue"),
        meta: { title: "首页", fixed: true ,icon: 'HomeFilled',breadcrumb: [{ title: '首页', path: '/home' }]},
      },
      {
        path: "/dashboard/workplace",
        name: "Workspace",
        component: () => import("@/views/dashboard/workspace.vue"),
        meta: { title: "工作台", fixed: true ,icon: 'dashboard'},
      },
      {
        path: "/dashboard/analytics",
        name: "Analytics",
        component: () => import("@/views/dashboard/analytics.vue"),
        meta: { title: "分析页", fixed: true,icon:'' },
      },
      {
        path: "/visualization/screen",
        name: "Screen",
        component: () => import("@/views/visualization/screen.vue"),
        meta: { title: "数据大屏", fixed: true ,icon:''},
      },
       {
        path: "/visualization/map",
        name: "Map",
        component: () => import("@/views/visualization/D3Map.vue"),
        meta: { title: "D3地图", fixed: true,icon:'' },
      },
      {
        path: "/list",
        name: "list",
        component: () => import("@/views/List.vue"),
        meta: { title: "列表页",icon:'' },
      },
      {
        path: "/details",
        name: "details",
        component: () => import("@/views/Details.vue"),
        meta: { title: "详情页面",icon:'' },
      },
      {
        path: "/setting",
        name: "Setting",
        component: () => import("@/views/setting/index.vue"),
        meta: { title: "系统设置",icon:'' },
      },
      {
        path: "/:pathMatch(.*)*", // 匹配所有未定义的路由
        name: "NotFound",
        meta: { title: "404页面",icon:'' },
        component: NotFound,
      },
    ],
  },
];
